<?php
namespace Admin\Model;
use Think\Model;

class SystemModel extends Model{
	protected $autoCheckFields = false;
	//自动验证
	protected $_validate = array(
		array('web_name','require','站点名称不得为空！',self::EXISTS_VALIDATE),
		array('admin_mail','require','管理员邮箱不得为空！',self::EXISTS_VALIDATE),
		array('manage_enter','require','后台入口不得为空！',self::EXISTS_VALIDATE),
		array('order_time','number','防刷单间隔必须是数字！',self::EXISTS_VALIDATE),
		array('order_mail_subject','require','订单提醒邮件标题不得为空！',self::EXISTS_VALIDATE),
		array('order_mail_content','require','订单提醒邮件内容不得为空！',self::EXISTS_VALIDATE),
		array('pay_mail_subject','require','支付提醒邮件标题不得为空！',self::EXISTS_VALIDATE),
		array('pay_mail_content','require','支付提醒邮件内容不得为空！',self::EXISTS_VALIDATE),
		array('send_mail_subject','require','发货提醒邮件标题不得为空！',self::EXISTS_VALIDATE),
		array('send_mail_content','require','发货提醒邮件内容不得为空！',self::EXISTS_VALIDATE),
	);
	
	//表单验证
	public function form(){
		$data = array(
			'web_name'=>I('post.web_name'),
			'admin_mail'=>I('post.admin_mail'),
			'manage_enter'=>I('post.manage_enter'),
			'order_time'=>I('post.order_time'),
			'order_mail_subject'=>I('post.order_mail_subject'),
			'order_mail_content'=>I('post.order_mail_content'),
			'pay_mail_subject'=>I('post.pay_mail_subject'),
			'pay_mail_content'=>I('post.pay_mail_content'),
			'send_mail_subject'=>I('post.send_mail_subject'),
			'send_mail_content'=>I('post.send_mail_content')
		);
		if ($this->create($data)){
			if (substr(I('post.manage_enter'),-4) != '.php') return '后台入口必须以.php结尾！';
			if (I('post.manage_enter',NULL,'strtolower') == 'admin.php') return '后台入口不得是admin.php！';
			if (I('post.manage_enter')!=I('post.old_manage_enter') && is_file(ROOT_PATH.'/'.I('post.manage_enter'))) return '系统根目录中已存在'.I('post.manage_enter').'文件，请重新指定一个后台入口！';
			return 1;
		}else{
			return $this->getError();
		}
	}
}